{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# pip install with locked versions\n",
    "! pip install -U pip\n",
    "! pip install -U clearml==0.16.2rc0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from clearml import Task\n",
    "from clearml.automation.controller import PipelineController"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "task = Task.init(project_name='Tabular Example', task_name='tabular training pipeline', task_type=Task.TaskTypes.controller)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe = PipelineController(default_execution_queue='dan_queue', add_pipeline_tags=True)\n",
    "pipe.add_step(name='preprocessing_1', base_task_project='Tabular Example', base_task_name='tabular preprocessing',\n",
    "              parameter_override={'General/data_task_id': '39fbf86fc4a341359ac6df4aa70ff91b',\n",
    "                                  'General/fill_categorical_NA': 'True',\n",
    "                                  'General/fill_numerical_NA': 'True'})\n",
    "pipe.add_step(name='preprocessing_2', base_task_project='Tabular Example', base_task_name='tabular preprocessing',\n",
    "              parameter_override={'General/data_task_id': '39fbf86fc4a341359ac6df4aa70ff91b',\n",
    "                                  'General/fill_categorical_NA': 'False',\n",
    "                                  'General/fill_numerical_NA': 'True'})\n",
    "                                  \n",
    "pipe.add_step(name='train_1', parents=['preprocessing_1'],\n",
    "              base_task_project='Tabular Example', base_task_name='tabular prediction',\n",
    "              parameter_override={'General/data_task_id': '${preprocessing_1.id}'})\n",
    "pipe.add_step(name='train_2', parents=['preprocessing_2'],\n",
    "              base_task_project='Tabular Example', base_task_name='tabular prediction',\n",
    "              parameter_override={'General/data_task_id': '${preprocessing_2.id}'})\n",
    "                                  \n",
    "pipe.add_step(name='pick_best', parents=['train_1', 'train_2'],\n",
    "              base_task_project='Tabular Example', base_task_name='pick best model',\n",
    "              parameter_override={'General/train_tasks_ids': '[${train_1.id}, ${train_2.id}]'})                   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Starting the pipeline (in the background)\n",
    "pipe.start()\n",
    "# Wait until pipeline terminates\n",
    "pipe.wait()\n",
    "# cleanup everything\n",
    "pipe.stop()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
